﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Reflection;
using System.IO;

namespace StateManager
{
    /// <summary>
    /// 信号类
    /// </summary>
    /// <typeparam name="T"></typeparam>
    [System.Runtime.InteropServices.ComVisible(true)]
    public class Signal<T>
    {
        public Signal()
        {
        }
        public Signal(dOnChanged fun)
        {
            OnChanged = fun;
        }
        T oldvalue = default;
        /// <summary>
        /// 上上次更新的值
        /// </summary>
        public T OldValue
        {
            get { return oldvalue; }
        }
        T value = default;
        /// <summary>
        /// 上次更新的值
        /// </summary>
        public T Value
        {
            get { return value; }
            set
            {
                oldvalue = this.value;
                this.value = value;
                if (!this.value.Equals(oldvalue))
                {
                    Changed = true;
                    if (OnChanged != null) OnChanged(this);
                }
                else
                {
                    if (Changed)
                    {
                        Changed = false;
                    }
                }
            }
        }
        /// <summary>
        /// 上次更新值有变化
        /// </summary>
        public bool Changed = false;
        public delegate void dOnChanged(Signal<T> sender);
        public dOnChanged OnChanged;

    }
}

